import { NextResponse } from "next/server";
import { getFoodTrucksList } from "@/app/actions";

export const GET = async () => {
  const data = await getFoodTrucksList({
    orderBy: {
      likeNum: "asc",
    },
    take: 50,
  });

  return NextResponse.json({
    success: true,
    message: "",
    data,
  });
};

export const POST = async (req) => {
  const params = await req.json();
  const { address, food } = params;
  console.log(address, food);

  const data =
    (await getFoodTrucksList({
      where: {
        AND: [
          { address: { contains: address } },
          { foodItems: { contains: food } },
        ],
      },
    })) || [];

  return NextResponse.json({
    success: true,
    message: "",
    data,
  });
};
